package com.jjb.www.ui.activity;

import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import com.hjq.base.BaseAdapter;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.jjb.www.R;
import com.jjb.www.app.AppActivity;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.http.api.HistoryListApi;
import com.jjb.www.http.model.HttpListData;
import com.jjb.www.ui.adapter.HistoryListAdapter;
import com.jjb.www.widget.CommonRefreshView;

import java.util.List;

import okhttp3.Call;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2018/10/18
 *    desc   : 培训历史
 */
public class HistoryListActivity extends AppActivity implements BaseAdapter.OnItemClickListener {
    private CommonRefreshView mRefreshView;
    private HistoryListAdapter mAdapter;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_history_list;
    }

    @Override
    protected void initView() {
        mRefreshView = findViewById(R.id.refreshView);
        mAdapter = new HistoryListAdapter(getContext());
        mAdapter.setOnItemClickListener(this);
    }

    @Override
    protected void initData() {
        mRefreshView.setDataHelper(new CommonRefreshView.DataHelper<HistoryListApi.Bean>() {
            @Override
            public AppAdapter<HistoryListApi.Bean> getAdapter() {
                return mAdapter;
            }

            @Override
            public void loadData(int p, HttpCallback<HttpListData<HistoryListApi.Bean>> callback) {
                EasyHttp.get(HistoryListActivity.this)
                        .api(new HistoryListApi()
                                .setStatus("3")
                                .setPage(p)
                                .setPageSize(mAdapter.getSize())
                        ).request(new HttpCallback<HttpListData<HistoryListApi.Bean>>(HistoryListActivity.this) {

                    @Override
                    public void onStart(Call call) {

                    }

                    @Override
                    public void onSucceed(HttpListData<HistoryListApi.Bean> result) {
                        callback.onSucceed(result);
                    }

                    @Override
                    public void onFail(Exception e) {
                        super.onFail(e);
                        callback.onFail(e);
                    }

                    @Override
                    public void onEnd(Call call) {
                        super.onEnd(call);
                        callback.onEnd(call);
                    }
                });
            }

            @Override
            public void onRefreshSuccess(List<HistoryListApi.Bean> list, int listCount) {

            }

            @Override
            public void onRefreshFailure() {

            }

            @Override
            public void onLoadMoreSuccess(List<HistoryListApi.Bean> loadItemList, int loadItemCount) {

            }

            @Override
            public void onLoadMoreFailure() {

            }
        });
        mRefreshView.initData();
    }

    @Override
    public void onItemClick(RecyclerView recyclerView, View itemView, int position) {

    }
}